﻿#include "MentorDialog.h"
#include "../../MirGraphics/MLibrary.h"
#include "../../MirSounds/SoundManager.h"
#include "../../../Shared/Language.h"
#include "../../Settings.h"
#include "../GameScene.h"

using namespace Client::MirControls;
using namespace Client::MirGraphics;
using namespace Client::MirNetwork;
using namespace Client::MirSounds;
namespace C = ClientPackets;

namespace Client::MirScenes::Dialogs
{

    MentorDialog::MentorDialog()
    {
        setIndex(170);
        setLibrary(Libraries::Prguse);
        setMovable(true);
        setSort(true);
        setLocation(getCenter());


        TitleLabel = new MirImageControl();
        TitleLabel->setIndex(51);
        TitleLabel->setLibrary(Libraries::Title);
        Point tempVar(18, 8);
        TitleLabel->setLocation(&tempVar);
        TitleLabel->setParent(this);



        CloseButton = new MirButton();
        CloseButton->setHoverIndex(361);
        CloseButton->setIndex(360);
        Point tempVar2(219, 3);
        CloseButton->setLocation(&tempVar2);
        CloseButton->setLibrary(Libraries::Prguse2);
        CloseButton->setParent(this);
        CloseButton->setPressedIndex(362);
        CloseButton->setSound(SoundList::ButtonA);
        CloseButton->Click += [&] (o, e)
        {
            Hide();
        };

        AllowButton = new MirButton();
        AllowButton->setHoverIndex(115);
        AllowButton->setIndex(114);
        Point tempVar3(30, 178);
        AllowButton->setLocation(&tempVar3);
        AllowButton->setLibrary(Libraries::Prguse);
        AllowButton->setParent(this);
        AllowButton->setPressedIndex(116);
        AllowButton->setSound(SoundList::ButtonA);
        AllowButton->setHint(GameLanguage::MentorRequests);
        AllowButton->Click += [&] (o, e)
        {
            if (AllowButton->getIndex() == 116)
            {
                AllowButton->setIndex(117);
                AllowButton->setHoverIndex(118);
                AllowButton->setPressedIndex(119);
            }
            else
            {
                AllowButton->setIndex(114);
                AllowButton->setHoverIndex(115);
                AllowButton->setPressedIndex(116);
            }
    
            C::AllowMentor tempVar4();
            Network::Enqueue(&tempVar4);
        };


        AddButton = new MirButton();
        AddButton->setHoverIndex(214);
        AddButton->setIndex(213);
        Point tempVar5(60, 178);
        AddButton->setLocation(&tempVar5);
        AddButton->setLibrary(Libraries::Title);
        AddButton->setParent(this);
        AddButton->setPressedIndex(215);
        AddButton->setSound(SoundList::ButtonA);
        AddButton->setHint(GameLanguage::AddMentor);
        AddButton->Click += [&] (o, e)
        {
            if (MentorLevel != 0)
            {
                GameScene::Scene->ChatDialog->ReceiveChat("You already have a Mentor.", ChatType::System);
                return;
            }
    
            std::string message = GameLanguage::MentorEnterName;
    
            MirInputBox *inputBox = new MirInputBox(message);
    
            inputBox->OKButton->Click += [&] (o1, e1)
            {
                    C::AddMentor *tempVar6 = new C::AddMentor();
                    tempVar6->Name = inputBox->InputTextBox->getText();
                    Network::Enqueue(tempVar6);
                    inputBox->Dispose();

//C# TO C++ CONVERTER TODO TASK: A 'delete tempVar6' statement was not added since tempVar6 was passed to a method or constructor. Handle memory management manually.
            };
    
            inputBox->Show();
    

            delete inputBox;
        };

        RemoveButton = new MirButton();
        RemoveButton->setHoverIndex(217);
        RemoveButton->setIndex(216);
        Point tempVar7(135, 178);
        RemoveButton->setLocation(&tempVar7);
        RemoveButton->setLibrary(Libraries::Title);
        RemoveButton->setParent(this);
        RemoveButton->setPressedIndex(218);
        RemoveButton->setSound(SoundList::ButtonA);
        RemoveButton->setHint(GameLanguage::RemoveMentorMentee);
        RemoveButton->Click += [&] (o, e)
        {
            if (MentorName == "")
            {
                GameScene::Scene->ChatDialog->ReceiveChat(GameLanguage::NoMentorship, ChatType::System);
                return;
            }
    
            MirMessageBox *messageBox = new MirMessageBox(std::string::Format("Cancelling a Mentorship early will cause a cooldown. Are you sure?"), MirMessageBoxButtons::YesNo);
    
            messageBox->YesButton->Click += [&] (oo, ee)
            {
                Network::Enqueue(new C::CancelMentor { });
            };
            messageBox->NoButton->Click += [&] (oo, ee)
            {
                    messageBox->Dispose();
            };
    
            messageBox->Show();
    

            delete messageBox;
        };

        MentorNameLabel = new MirLabel();
        Point tempVar8(20, 58);
        MentorNameLabel->setLocation(&tempVar8);
        Size tempVar9(200, 30);
        MentorNameLabel->setSize(&tempVar9);
        MentorNameLabel->setBackColour(Color::Empty);
        MentorNameLabel->setForeColour(Color::LightGray);
        MentorNameLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        MentorNameLabel->setParent(this);
        MentorNameLabel->setNotControl(true);
        Font tempVar10(Settings::FontName, 10.0F);
        MentorNameLabel->setFont(&tempVar10);

        MentorLevelLabel = new MirLabel();
        Point tempVar11(170, 58);
        MentorLevelLabel->setLocation(&tempVar11);
        Size tempVar12(200, 30);
        MentorLevelLabel->setSize(&tempVar12);
        MentorLevelLabel->setBackColour(Color::Empty);
        MentorLevelLabel->setForeColour(Color::LightGray);
        MentorLevelLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        MentorLevelLabel->setParent(this);
        MentorLevelLabel->setNotControl(true);
        Font tempVar13(Settings::FontName, 10.0F);
        MentorLevelLabel->setFont(&tempVar13);

        MentorOnlineLabel = new MirLabel();
        Point tempVar14(125, 58);
        MentorOnlineLabel->setLocation(&tempVar14);
        Size tempVar15(200, 30);
        MentorOnlineLabel->setSize(&tempVar15);
        MentorOnlineLabel->setBackColour(Color::Empty);
        MentorOnlineLabel->setForeColour(Color::Green);
        MentorOnlineLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        MentorOnlineLabel->setParent(this);
        MentorOnlineLabel->setNotControl(true);
        Font tempVar16(Settings::FontName, 7.0F);
        MentorOnlineLabel->setFont(&tempVar16);
        MentorOnlineLabel->setVisible(false);
        MentorOnlineLabel->setText("ONLINE");

        StudentNameLabel = new MirLabel();
        Point tempVar17(20, 112);
        StudentNameLabel->setLocation(&tempVar17);
        Size tempVar18(200, 30);
        StudentNameLabel->setSize(&tempVar18);
        StudentNameLabel->setBackColour(Color::Empty);
        StudentNameLabel->setForeColour(Color::LightGray);
        StudentNameLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        StudentNameLabel->setParent(this);
        StudentNameLabel->setNotControl(true);
        Font tempVar19(Settings::FontName, 10.0F);
        StudentNameLabel->setFont(&tempVar19);

        StudentLevelLabel = new MirLabel();
        Point tempVar20(170, 111);
        StudentLevelLabel->setLocation(&tempVar20);
        Size tempVar21(200, 30);
        StudentLevelLabel->setSize(&tempVar21);
        StudentLevelLabel->setBackColour(Color::Empty);
        StudentLevelLabel->setForeColour(Color::LightGray);
        StudentLevelLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        StudentLevelLabel->setParent(this);
        StudentLevelLabel->setNotControl(true);
        Font tempVar22(Settings::FontName, 10.0F);
        StudentLevelLabel->setFont(&tempVar22);

        StudentOnlineLabel = new MirLabel();
        Point tempVar23(125, 112);
        StudentOnlineLabel->setLocation(&tempVar23);
        Size tempVar24(200, 30);
        StudentOnlineLabel->setSize(&tempVar24);
        StudentOnlineLabel->setBackColour(Color::Empty);
        StudentOnlineLabel->setForeColour(Color::Green);
        StudentOnlineLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        StudentOnlineLabel->setParent(this);
        StudentOnlineLabel->setNotControl(true);
        Font tempVar25(Settings::FontName, 7.0F);
        StudentOnlineLabel->setFont(&tempVar25);
        StudentOnlineLabel->setVisible(false);
        StudentOnlineLabel->setText("ONLINE");

        MentorLabel = new MirLabel();
        Point tempVar26(15, 41);
        MentorLabel->setLocation(&tempVar26);
        Size tempVar27(200, 30);
        MentorLabel->setSize(&tempVar27);
        MentorLabel->setBackColour(Color::Empty);
        MentorLabel->setForeColour(Color::DimGray);
        MentorLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        MentorLabel->setParent(this);
        MentorLabel->setNotControl(true);
        Font tempVar28(Settings::FontName, 7.0F);
        MentorLabel->setFont(&tempVar28);
        MentorLabel->setText("MENTOR");

        StudentLabel = new MirLabel();
        Point tempVar29(15, 94);
        StudentLabel->setLocation(&tempVar29);
        Size tempVar30(200, 30);
        StudentLabel->setSize(&tempVar30);
        StudentLabel->setBackColour(Color::Empty);
        StudentLabel->setForeColour(Color::DimGray);
        StudentLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        StudentLabel->setParent(this);
        StudentLabel->setNotControl(true);
        Font tempVar31(Settings::FontName, 7.0F);
        StudentLabel->setFont(&tempVar31);
        StudentLabel->setText("MENTEE");

        MenteeEXPLabel = new MirLabel();
        Point tempVar32(15, 147);
        MenteeEXPLabel->setLocation(&tempVar32);
        Size tempVar33(200, 30);
        MenteeEXPLabel->setSize(&tempVar33);
        MenteeEXPLabel->setBackColour(Color::Empty);
        MenteeEXPLabel->setForeColour(Color::DimGray);
        MenteeEXPLabel->setDrawFormat(TextFormatFlags::VerticalCenter);
        MenteeEXPLabel->setParent(this);
        MenteeEXPLabel->setNotControl(true);
        Font tempVar34(Settings::FontName, 7.0F);
        MenteeEXPLabel->setFont(&tempVar34);




    }

    void MentorDialog::UpdateInterface()
    {
        if (MentorLevel == 0)
        {
            MentorNameLabel->setVisible(false);
            MentorLevelLabel->setVisible(false);
            MentorOnlineLabel->setVisible(false);
            StudentNameLabel->setVisible(false);
            StudentLevelLabel->setVisible(false);
            StudentOnlineLabel->setVisible(false);
            MenteeEXPLabel->setVisible(false);
            return;
        }

        MentorNameLabel->setVisible(true);
        MentorLevelLabel->setVisible(true);
        MentorOnlineLabel->setVisible(true);
        StudentNameLabel->setVisible(true);
        StudentLevelLabel->setVisible(true);
        StudentOnlineLabel->setVisible(true);

        if (GameScene::getUser()->Level > MentorLevel)
        {
            MentorNameLabel->setText(GameScene::getUser()->Name);
            MentorLevelLabel->setText("Lv " + std::to_string(GameScene::getUser()->Level));
            MentorOnlineLabel->setVisible(false);

            StudentNameLabel->setText(MentorName);
            StudentLevelLabel->setText("Lv " + std::to_string(MentorLevel));
            if (MentorOnline)
            {
                StudentOnlineLabel->setVisible(true);
            }
            else
            {
                StudentOnlineLabel->setVisible(false);
            }

            MenteeEXPLabel->setVisible(true);
            MenteeEXPLabel->setText("MENTEE EXP: " + std::to_string(MenteeEXP));
        }
        else
        {
            MentorNameLabel->setText(MentorName);
            MentorLevelLabel->setText("Lv " + std::to_string(MentorLevel));
            if (MentorOnline)
            {
                MentorOnlineLabel->setVisible(true);
            }
            else
            {
                MentorOnlineLabel->setVisible(false);
            }

            StudentNameLabel->setText(GameScene::getUser()->Name);
            StudentLevelLabel->setText("Lv " + std::to_string(GameScene::getUser()->Level));
            StudentOnlineLabel->setVisible(false);
        }
    }
}
